package org.example.myleet.Utils;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class NetworkDigUtil {
    public static void main(String[] args) {
        String base = "http://192.168.1.";
        for (int i = 200; i < 256; ++i) {
            String address = base + i + ":80/";
            tryConnect(address);
        }
//        tryConnect("http://192.168.1.235:80/");
    }

    private static void tryConnect(String address) {
        System.out.printf("try connecting %s...\n", address);
        URL url;
        try {
            url = new URL(address);
            URLConnection connection = url.openConnection();
            connection.setConnectTimeout(1000);
            InputStream inputStream = connection.getInputStream();
            printStream(inputStream);
        } catch (Exception e) {
            //ignore
            System.out.println(e.getMessage());
        }
    }

    private static void printStream(InputStream inputStream) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        while (br.ready()) {
            System.out.println(br.readLine());
        }
        br.close();
    }
}
